package com.atxiao.demo.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class CodeController {

    @RequestMapping("/getImage")
    public void getImage(HttpSession session, HttpServletResponse response) throws IOException, IOException {
        //生成验证码
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(100, 50, 4, 4);
        //验证码放入session
        session.setAttribute("code", captcha.getCode());
        //写出到浏览器（Servlet输出）
        captcha.write(response.getOutputStream());
        System.out.println(captcha.getCode());
    }


}
